<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
 <head>
  <title>cpteqr.f</title>
 <meta name="generator" content="emacs 21.3.1; htmlfontify 0.20">
<style type="text/css"><!-- 
body { background: rgb(255, 255, 255);  color: rgb(0, 0, 0);  font-style: normal;  font-weight: 500;  font-stretch: normal;  font-family: adobe-courier;  font-size: 11pt;  text-decoration: none; }
span.default   { background: rgb(255, 255, 255);  color: rgb(0, 0, 0);  font-style: normal;  font-weight: 500;  font-stretch: normal;  font-family: adobe-courier;  font-size: 11pt;  text-decoration: none; }
span.default a { background: rgb(255, 255, 255);  color: rgb(0, 0, 0);  font-style: normal;  font-weight: 500;  font-stretch: normal;  font-family: adobe-courier;  font-size: 11pt;  text-decoration: underline; }
span.string   { color: rgb(188, 143, 143);  background: rgb(255, 255, 255);  font-style: normal;  font-weight: 500;  font-stretch: normal;  font-family: adobe-courier;  font-size: 11pt;  text-decoration: none; }
span.string a { color: rgb(188, 143, 143);  background: rgb(255, 255, 255);  font-style: normal;  font-weight: 500;  font-stretch: normal;  font-family: adobe-courier;  font-size: 11pt;  text-decoration: underline; }
span.comment   { color: rgb(178, 34, 34);  background: rgb(255, 255, 255);  font-style: normal;  font-weight: 500;  font-stretch: normal;  font-family: adobe-courier;  font-size: 11pt;  text-decoration: none; }
span.comment a { color: rgb(178, 34, 34);  background: rgb(255, 255, 255);  font-style: normal;  font-weight: 500;  font-stretch: normal;  font-family: adobe-courier;  font-size: 11pt;  text-decoration: underline; }
 --></style>

 </head>
  <body>

<pre>
      SUBROUTINE <a name="CPTEQR.1"></a><a href="cpteqr.f.html#CPTEQR.1">CPTEQR</a>( COMPZ, N, D, E, Z, LDZ, WORK, INFO )
<span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">  -- LAPACK routine (version 3.1) --
</span><span class="comment">*</span><span class="comment">     Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd..
</span><span class="comment">*</span><span class="comment">     November 2006
</span><span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">     .. Scalar Arguments ..
</span>      CHARACTER          COMPZ
      INTEGER            INFO, LDZ, N
<span class="comment">*</span><span class="comment">     ..
</span><span class="comment">*</span><span class="comment">     .. Array Arguments ..
</span>      REAL               D( * ), E( * ), WORK( * )
      COMPLEX            Z( LDZ, * )
<span class="comment">*</span><span class="comment">     ..
</span><span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">  Purpose
</span><span class="comment">*</span><span class="comment">  =======
</span><span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">  <a name="CPTEQR.19"></a><a href="cpteqr.f.html#CPTEQR.1">CPTEQR</a> computes all eigenvalues and, optionally, eigenvectors of a
</span><span class="comment">*</span><span class="comment">  symmetric positive definite tridiagonal matrix by first factoring the
</span><span class="comment">*</span><span class="comment">  matrix using <a name="SPTTRF.21"></a><a href="spttrf.f.html#SPTTRF.1">SPTTRF</a> and then calling <a name="CBDSQR.21"></a><a href="cbdsqr.f.html#CBDSQR.1">CBDSQR</a> to compute the singular
</span><span class="comment">*</span><span class="comment">  values of the bidiagonal factor.
</span><span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">  This routine computes the eigenvalues of the positive definite
</span><span class="comment">*</span><span class="comment">  tridiagonal matrix to high relative accuracy.  This means that if the
</span><span class="comment">*</span><span class="comment">  eigenvalues range over many orders of magnitude in size, then the
</span><span class="comment">*</span><span class="comment">  small eigenvalues and corresponding eigenvectors will be computed
</span><span class="comment">*</span><span class="comment">  more accurately than, for example, with the standard QR method.
</span><span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">  The eigenvectors of a full or band positive definite Hermitian matrix
</span><span class="comment">*</span><span class="comment">  can also be found if <a name="CHETRD.31"></a><a href="chetrd.f.html#CHETRD.1">CHETRD</a>, <a name="CHPTRD.31"></a><a href="chptrd.f.html#CHPTRD.1">CHPTRD</a>, or <a name="CHBTRD.31"></a><a href="chbtrd.f.html#CHBTRD.1">CHBTRD</a> has been used to
</span><span class="comment">*</span><span class="comment">  reduce this matrix to tridiagonal form.  (The reduction to
</span><span class="comment">*</span><span class="comment">  tridiagonal form, however, may preclude the possibility of obtaining
</span><span class="comment">*</span><span class="comment">  high relative accuracy in the small eigenvalues of the original
</span><span class="comment">*</span><span class="comment">  matrix, if these eigenvalues range over many orders of magnitude.)
</span><span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">  Arguments
</span><span class="comment">*</span><span class="comment">  =========
</span><span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">  COMPZ   (input) CHARACTER*1
</span><span class="comment">*</span><span class="comment">          = 'N':  Compute eigenvalues only.
</span><span class="comment">*</span><span class="comment">          = 'V':  Compute eigenvectors of original Hermitian
</span><span class="comment">*</span><span class="comment">                  matrix also.  Array Z contains the unitary matrix
</span><span class="comment">*</span><span class="comment">                  used to reduce the original matrix to tridiagonal
</span><span class="comment">*</span><span class="comment">                  form.
</span><span class="comment">*</span><span class="comment">          = 'I':  Compute eigenvectors of tridiagonal matrix also.
</span><span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">  N       (input) INTEGER
</span><span class="comment">*</span><span class="comment">          The order of the matrix.  N &gt;= 0.
</span><span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">  D       (input/output) REAL array, dimension (N)
</span><span class="comment">*</span><span class="comment">          On entry, the n diagonal elements of the tridiagonal matrix.
</span><span class="comment">*</span><span class="comment">          On normal exit, D contains the eigenvalues, in descending
</span><span class="comment">*</span><span class="comment">          order.
</span><span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">  E       (input/output) REAL array, dimension (N-1)
</span><span class="comment">*</span><span class="comment">          On entry, the (n-1) subdiagonal elements of the tridiagonal
</span><span class="comment">*</span><span class="comment">          matrix.
</span><span class="comment">*</span><span class="comment">          On exit, E has been destroyed.
</span><span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">  Z       (input/output) COMPLEX array, dimension (LDZ, N)
</span><span class="comment">*</span><span class="comment">          On entry, if COMPZ = 'V', the unitary matrix used in the
</span><span class="comment">*</span><span class="comment">          reduction to tridiagonal form.
</span><span class="comment">*</span><span class="comment">          On exit, if COMPZ = 'V', the orthonormal eigenvectors of the
</span><span class="comment">*</span><span class="comment">          original Hermitian matrix;
</span><span class="comment">*</span><span class="comment">          if COMPZ = 'I', the orthonormal eigenvectors of the
</span><span class="comment">*</span><span class="comment">          tridiagonal matrix.
</span><span class="comment">*</span><span class="comment">          If INFO &gt; 0 on exit, Z contains the eigenvectors associated
</span><span class="comment">*</span><span class="comment">          with only the stored eigenvalues.
</span><span class="comment">*</span><span class="comment">          If  COMPZ = 'N', then Z is not referenced.
</span><span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">  LDZ     (input) INTEGER
</span><span class="comment">*</span><span class="comment">          The leading dimension of the array Z.  LDZ &gt;= 1, and if
</span><span class="comment">*</span><span class="comment">          COMPZ = 'V' or 'I', LDZ &gt;= max(1,N).
</span><span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">  WORK    (workspace) REAL array, dimension (4*N)
</span><span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">  INFO    (output) INTEGER
</span><span class="comment">*</span><span class="comment">          = 0:  successful exit.
</span><span class="comment">*</span><span class="comment">          &lt; 0:  if INFO = -i, the i-th argument had an illegal value.
</span><span class="comment">*</span><span class="comment">          &gt; 0:  if INFO = i, and i is:
</span><span class="comment">*</span><span class="comment">                &lt;= N  the Cholesky factorization of the matrix could
</span><span class="comment">*</span><span class="comment">                      not be performed because the i-th principal minor
</span><span class="comment">*</span><span class="comment">                      was not positive definite.
</span><span class="comment">*</span><span class="comment">                &gt; N   the SVD algorithm failed to converge;
</span><span class="comment">*</span><span class="comment">                      if INFO = N+i, i off-diagonal elements of the
</span><span class="comment">*</span><span class="comment">                      bidiagonal factor did not converge to zero.
</span><span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">  ====================================================================
</span><span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">     .. Parameters ..
</span>      COMPLEX            CZERO, CONE
      PARAMETER          ( CZERO = ( 0.0E+0, 0.0E+0 ),
     $                   CONE = ( 1.0E+0, 0.0E+0 ) )
<span class="comment">*</span><span class="comment">     ..
</span><span class="comment">*</span><span class="comment">     .. External Functions ..
</span>      LOGICAL            <a name="LSAME.97"></a><a href="lsame.f.html#LSAME.1">LSAME</a>
      EXTERNAL           <a name="LSAME.98"></a><a href="lsame.f.html#LSAME.1">LSAME</a>
<span class="comment">*</span><span class="comment">     ..
</span><span class="comment">*</span><span class="comment">     .. External Subroutines ..
</span>      EXTERNAL           <a name="CBDSQR.101"></a><a href="cbdsqr.f.html#CBDSQR.1">CBDSQR</a>, <a name="CLASET.101"></a><a href="claset.f.html#CLASET.1">CLASET</a>, <a name="SPTTRF.101"></a><a href="spttrf.f.html#SPTTRF.1">SPTTRF</a>, <a name="XERBLA.101"></a><a href="xerbla.f.html#XERBLA.1">XERBLA</a>
<span class="comment">*</span><span class="comment">     ..
</span><span class="comment">*</span><span class="comment">     .. Local Arrays ..
</span>      COMPLEX            C( 1, 1 ), VT( 1, 1 )
<span class="comment">*</span><span class="comment">     ..
</span><span class="comment">*</span><span class="comment">     .. Local Scalars ..
</span>      INTEGER            I, ICOMPZ, NRU
<span class="comment">*</span><span class="comment">     ..
</span><span class="comment">*</span><span class="comment">     .. Intrinsic Functions ..
</span>      INTRINSIC          MAX, SQRT
<span class="comment">*</span><span class="comment">     ..
</span><span class="comment">*</span><span class="comment">     .. Executable Statements ..
</span><span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">     Test the input parameters.
</span><span class="comment">*</span><span class="comment">
</span>      INFO = 0
<span class="comment">*</span><span class="comment">
</span>      IF( <a name="LSAME.118"></a><a href="lsame.f.html#LSAME.1">LSAME</a>( COMPZ, <span class="string">'N'</span> ) ) THEN
         ICOMPZ = 0
      ELSE IF( <a name="LSAME.120"></a><a href="lsame.f.html#LSAME.1">LSAME</a>( COMPZ, <span class="string">'V'</span> ) ) THEN
         ICOMPZ = 1
      ELSE IF( <a name="LSAME.122"></a><a href="lsame.f.html#LSAME.1">LSAME</a>( COMPZ, <span class="string">'I'</span> ) ) THEN
         ICOMPZ = 2
      ELSE
         ICOMPZ = -1
      END IF
      IF( ICOMPZ.LT.0 ) THEN
         INFO = -1
      ELSE IF( N.LT.0 ) THEN
         INFO = -2
      ELSE IF( ( LDZ.LT.1 ) .OR. ( ICOMPZ.GT.0 .AND. LDZ.LT.MAX( 1,
     $         N ) ) ) THEN
         INFO = -6
      END IF
      IF( INFO.NE.0 ) THEN
         CALL <a name="XERBLA.136"></a><a href="xerbla.f.html#XERBLA.1">XERBLA</a>( <span class="string">'<a name="CPTEQR.136"></a><a href="cpteqr.f.html#CPTEQR.1">CPTEQR</a>'</span>, -INFO )
         RETURN
      END IF
<span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">     Quick return if possible
</span><span class="comment">*</span><span class="comment">
</span>      IF( N.EQ.0 )
     $   RETURN
<span class="comment">*</span><span class="comment">
</span>      IF( N.EQ.1 ) THEN
         IF( ICOMPZ.GT.0 )
     $      Z( 1, 1 ) = CONE
         RETURN
      END IF
      IF( ICOMPZ.EQ.2 )
     $   CALL <a name="CLASET.151"></a><a href="claset.f.html#CLASET.1">CLASET</a>( <span class="string">'Full'</span>, N, N, CZERO, CONE, Z, LDZ )
<span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">     Call <a name="SPTTRF.153"></a><a href="spttrf.f.html#SPTTRF.1">SPTTRF</a> to factor the matrix.
</span><span class="comment">*</span><span class="comment">
</span>      CALL <a name="SPTTRF.155"></a><a href="spttrf.f.html#SPTTRF.1">SPTTRF</a>( N, D, E, INFO )
      IF( INFO.NE.0 )
     $   RETURN
      DO 10 I = 1, N
         D( I ) = SQRT( D( I ) )
   10 CONTINUE
      DO 20 I = 1, N - 1
         E( I ) = E( I )*D( I )
   20 CONTINUE
<span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">     Call <a name="CBDSQR.165"></a><a href="cbdsqr.f.html#CBDSQR.1">CBDSQR</a> to compute the singular values/vectors of the
</span><span class="comment">*</span><span class="comment">     bidiagonal factor.
</span><span class="comment">*</span><span class="comment">
</span>      IF( ICOMPZ.GT.0 ) THEN
         NRU = N
      ELSE
         NRU = 0
      END IF
      CALL <a name="CBDSQR.173"></a><a href="cbdsqr.f.html#CBDSQR.1">CBDSQR</a>( <span class="string">'Lower'</span>, N, 0, NRU, 0, D, E, VT, 1, Z, LDZ, C, 1,
     $             WORK, INFO )
<span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">     Square the singular values.
</span><span class="comment">*</span><span class="comment">
</span>      IF( INFO.EQ.0 ) THEN
         DO 30 I = 1, N
            D( I ) = D( I )*D( I )
   30    CONTINUE
      ELSE
         INFO = N + INFO
      END IF
<span class="comment">*</span><span class="comment">
</span>      RETURN
<span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">     End of <a name="CPTEQR.188"></a><a href="cpteqr.f.html#CPTEQR.1">CPTEQR</a>
</span><span class="comment">*</span><span class="comment">
</span>      END

</pre>

 </body>
</html>
